package com.fxkj.cloud.drms.domain.device.repository;

import com.fxkj.cloud.dbs.common.constants.DeviceStatusEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>description: </p>
 * @author ww
 * @date 2025/4/10 17:19
 */
@Getter
public class ProductDeviceStatusStatistics {
    private final Long ts;
    private final Long sumCount;
    private final Long offlineCount;
    private final String offlineRate;
    private final Long onlineCount;
    private final String onlineRate;
    private final Long workingCount;
    private final String workingRate;
    private final Long alarmingCount;
    private final String alarmingRate;

    public ProductDeviceStatusStatistics(Long ts, Long sumCount, Long offlineCount, Long onlineCount, Long workingCount, Long alarmingCount) {
        this.ts = ts;
        this.sumCount = sumCount;
        if (sumCount == 0) {
            this.offlineRate = "0%";
            this.onlineRate = "0%";
            this.workingRate = "0%";
            this.alarmingRate = "0%";
        } else {
            this.offlineRate = String.format("%.2f%%", (double) offlineCount / sumCount * 100);
            this.onlineRate = String.format("%.2f%%", (double) onlineCount / sumCount * 100);
            this.workingRate = String.format("%.2f%%", (double) workingCount / sumCount * 100);
            this.alarmingRate = String.format("%.2f%%", (double) alarmingCount / sumCount * 100);
        }
        this.offlineCount = offlineCount;
        this.onlineCount = onlineCount;
        this.workingCount = workingCount;
        this.alarmingCount = alarmingCount;
    }

    public static ProductDeviceStatusStatistics create(Long ts, Long sumCount, Long offlineCount, Long onlineCount, Long workingCount, Long alarmingCount) {
        return new ProductDeviceStatusStatistics(ts, sumCount, offlineCount, onlineCount, workingCount, alarmingCount);
    }
}
